﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{

    public class FLTMUORDERData : BaseFunction
    {
        
        public FLTMUORDERData()
            : base()
        {

        }
        public FLTMUORDERData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetVKPOS(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "MUORDER";
            string ARTICLE = dwABPOS["ARTICLE"].ToString().Trim();
            string FROMDATE = dwABPOS["fromdate"].ToString().Trim();
            string ENDDATE = dwABPOS["enddate"].ToString().Trim();         
            
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "select A.ABPAUFLFD,A.ABPAUFPOS,UPPER(B.GSGARNBEZ) AS ARTICLE, "
                + " A.ABPFARBE,A.ABPSOLLMENGE5*0.01 AS ORDQTY,A.ABPNEUDAT, "
                + " A.ABPZUGKG*0.01 AS ALLQTY,A.ABPEAKG*0.01 AS PRDQTY,(A.ABPZUGKG-A.ABPEAKG)*0.01 AS OPENQTY, "
                + " ROUND((CASE WHEN A.ABPZUGKG>0 THEN (A.ABPZUGKG-A.ABPEAKG)/A.ABPZUGKG ELSE 0 END)*100,2) AS RATE, "
                + " decode(A.ABPERLKZ,'J','FINISHED') AS ABPERLKZ "
                + " from ABPOS A,GSDAT B "
                + " where A.ABPMANDANT = B.GSMANDANT AND A.ABPART = B.GSART "
                + " AND A.ABPVAR = B.GSVAR AND A.ABPLOEKZ <>'J' "
                + " AND a.abppostyp = 'MU ' AND UPPER(B.GSGARNBEZ) LIKE '" + ARTICLE + "%' "
                + " AND A.ABPNEUDAT >='" + FROMDATE + "' AND A.ABPNEUDAT <= '" + ENDDATE + "' " 
                                      
                    ;
                
                Result = Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    /*byte[] b;
                    string value;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["REMARK"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["REMARK"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["BEM"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["BEM"] = value;
                    }*/
                }                
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }        
        public DataSet BuildFLTMUORDERData(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetVKPOS(dwUI);
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }        
        
    }
}